//
//  DM_SQLiteOpenHelper.swift
//  构建者模式_ORM_SWIFT
//
//  Created by 王苏进 on 17/5/17.
//  Copyright © 2017年 macOS. All rights reserved.
//

import UIKit

class DM_SQLiteOpenHelper: NSObject {

   private var dbName: String = "DM_Orm.db"
    
   private var dbVersion: String = "1"
    
   private var db:DM_OrmSQLiteDB?
    
    init(dbName:String, dbVersion: String) {
        
        super.init()
        self.dbName = dbName
        self.dbVersion = dbVersion
        
        self.db = DM_OrmSQLiteDB(dbName: self.dbName)
        
        if (UserDefaults.standard.object(forKey: "dbVersion") == nil) {
          
           self.onCreate(db: self.db!)
        
        }else{
            if self.dbVersion != dbVersion {
                 self.onUpdate(db: self.db!, dbVersion: self.dbVersion)
            }
            
        }
        
        //版本号需要保存到本地
        
        UserDefaults.standard.set(self.dbVersion, forKey: "dbVersion")
  
        
    }
    
   
    func onCreate(db: DM_OrmSQLiteDB) {
    
    
    }
    
    func onUpdate(db: DM_OrmSQLiteDB, dbVersion:String) {
        
        
    }
    
    func getDB() -> DM_OrmSQLiteDB? {
        return db
    }
    
    
    
    
}
